<script setup lang="ts">
import { ref } from 'vue'
import { Check, Warning, Plus } from '@element-plus/icons-vue'

interface Facility {
  id: number
  name: string
  location: string
  status: 'running' | 'maintenance' | 'repair'
  lastMaintenance: string
  nextMaintenance: string
  description: string
}

const facilities = ref<Facility[]>([
  {
    id: 1,
    name: '康复理疗室',
    location: '一楼东侧',
    status: 'running',
    lastMaintenance: '2024-02-15',
    nextMaintenance: '2024-04-15',
    description: '设备运行正常'
  },
  {
    id: 2,
    name: '多功能活动室',
    location: '一楼中央',
    status: 'running',
    lastMaintenance: '2024-02-20',
    nextMaintenance: '2024-04-20',
    description: '空调系统正常'
  },
  {
    id: 3,
    name: '医务室',
    location: '一楼西侧',
    status: 'running',
    lastMaintenance: '2024-03-01',
    nextMaintenance: '2024-05-01',
    description: '医疗设备定期消毒'
  }
])

const getStatusIcon = (status: string) => {
  switch (status) {
    case 'running':
      return Check
    case 'maintenance':
    case 'repair':
      return Warning
    default:
      return Check
  }
}

const getStatusColor = (status: string) => {
  switch (status) {
    case 'running':
      return '#67C23A'
    case 'maintenance':
      return '#E6A23C'
    case 'repair':
      return '#F56C6C'
    default:
      return '#67C23A'
  }
}

const getStatusText = (status: string) => {
  switch (status) {
    case 'running':
      return '运行中'
    case 'maintenance':
      return '维护中'
    case 'repair':
      return '维修中'
    default:
      return '运行中'
  }
}
</script>

<template>
  <div class="facility-management">
    <div class="page-header">
      <div class="header-content">
        <h1>设施维护</h1>
        <p class="subtitle">管理和监控所有设施的运行状态</p>
      </div>
      <el-button type="primary" class="add-button">
        <el-icon><Plus /></el-icon>
        添加设施
      </el-button>
    </div>

    <el-row :gutter="24">
      <el-col :span="8" v-for="facility in facilities" :key="facility.id">
        <el-card class="facility-card" shadow="hover">
          <div class="facility-header">
            <h3>{{ facility.name }}</h3>
            <div class="status-badge" :style="{ backgroundColor: `${getStatusColor(facility.status)}15` }">
              <el-icon :style="{ color: getStatusColor(facility.status) }">
                <component :is="getStatusIcon(facility.status)" />
              </el-icon>
              <span :style="{ color: getStatusColor(facility.status) }">
                {{ getStatusText(facility.status) }}
              </span>
            </div>
          </div>

          <div class="facility-info">
            <div class="info-item">
              <span class="label">位置</span>
              <span class="value">{{ facility.location }}</span>
            </div>
            <div class="info-item">
              <span class="label">上次维护</span>
              <span class="value">{{ facility.lastMaintenance }}</span>
            </div>
            <div class="info-item">
              <span class="label">下次维护</span>
              <span class="value">{{ facility.nextMaintenance }}</span>
            </div>
            <div class="info-item">
              <span class="label">状态说明</span>
              <span class="value">{{ facility.description }}</span>
            </div>
          </div>

          <div class="facility-actions">
            <el-button 
              type="primary" 
              plain
              class="action-button"
            >
              维护记录
            </el-button>
            <el-button 
              :type="facility.status === 'running' ? 'warning' : 'danger'"
              class="action-button"
            >
              {{ facility.status === 'running' ? '报修' : '查看维修' }}
            </el-button>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<style scoped lang="scss">
.facility-management {
  .page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 32px;

    .header-content {
      h1 {
        font-size: 28px;
        font-weight: 600;
        margin: 0 0 8px;
        color: var(--primary-text);
      }

      .subtitle {
        font-size: 16px;
        color: var(--secondary-text);
        margin: 0;
      }
    }

    .add-button {
      display: flex;
      align-items: center;
      gap: 8px;
      padding: 12px 24px;
      font-size: 16px;
    }
  }

  .facility-card {
    height: 100%;
    display: flex;
    flex-direction: column;
    margin-bottom: 24px;
    background-color: #ffffff;
    
    .facility-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 20px;
      
      h3 {
        margin: 0;
        font-size: 18px;
        font-weight: 600;
        color: var(--primary-text);
      }
      
      .status-badge {
        display: flex;
        align-items: center;
        gap: 6px;
        padding: 6px 12px;
        border-radius: 20px;
        
        .el-icon {
          font-size: 14px;
        }
        
        span {
          font-size: 14px;
          font-weight: 500;
        }
      }
    }
    
    .facility-info {
      flex: 1;
      .info-item {
        display: flex;
        margin-bottom: 16px;
        
        .label {
          width: 80px;
          color: var(--secondary-text);
          font-size: 14px;
        }
        
        .value {
          flex: 1;
          font-size: 14px;
          color: var(--primary-text);
        }
      }
    }
    
    .facility-actions {
      display: flex;
      gap: 12px;
      margin-top: 24px;
      
      .action-button {
        flex: 1;
        height: 40px;
        font-size: 14px;
        font-weight: 500;
        
        &:hover {
          transform: translateY(-1px);
        }
      }
    }
  }
}
</style>